home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
209
< prev
next >
Wrap
Text File
|
1996-08-06
|
3KB
|
108 lines
Path: news.compuserve.com!newsmaster
From: Piet Starreveld <101476.1040@compuserve.com>
Newsgroups: comp.std.c
Subject: Re: How to calculate the Holy Easter.
Date: 28 Jan 1996 18:34:48 GMT
Organization: CompuServe Incorporated
Message-ID: <4egfk8$clg@dub-news-svc-4.compuserve.com>
References: <4e5kmh$2g9@leporello.cs.unibo.it>
NNTP-Posting-Host: hd19-014.compuserve.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 1.22 (Windows; I; 16bit)
To: chierici@cs.unibo.it
Hi,
on January 24, 1996 you wrote:
> Hi, can anybody send me a C function to calculate the Easter of every
> year? Thanks in advance,
> Andrea.
Then this guy came up with a Gauss algorithm put into a Pascal (yagh!)
procedure:
Abe Timmerman
Hogeschool Holland
(HHIT: Center for education and Information Technology)
The Netherlands
Email:A.Timmerman@Beta.hsholland.nl
Next ofcourse somebody asked for the C version, which you did in the
first place.
Below you will find the Pascal procedure converted to a C function
and a (tested) sample program that calls the function. This is by far
not the most elegant C function I have ever seen, but it is meant
to follow the Pascal procedure step by step. I do not know if limits
for the year exist and if so what they are (besides ofcourse the obvious
ones), I did not test for any:
=========================================================================
#include <stdio.h>
void Easter(int * Month, int * Day, int Year);
void main()
{
int y, m, d;
for (y = 1800; y <= 2000; y++) {
Easter(&m, &d, y);
printf("Year: %4d, Month: %2d, Day: %2d\n", y, m, d);
}
}
/*
C version for the Gauss-Easter algorithm
Based on the formulas/algorithm published bij Gauss in 1800
Input: - pointers to ints Month and Day
- int Year where 1800 <= Year <= 2000 (?)
Input-validation: none (sensible input assumed for Year)
*/
void Easter(int * Month, int * Day, int Year)
{
int a, b, c, d, e, f, k, m, n, p, q;
a = Year % 19;
b = Year % 4;
c = Year % 7;
k = Year / 100;
p = k / 3;
q = k - k / 4;
m = (q - p + 15) % 30;
n = (q + 4) % 7;
d = (19 * a + m) % 30;
e = (2 * b + 4 * c + 6 * d + n) % 7;
f = d + e - 9;
if (f <= 0) {
*Month = 3;
*Day = 31 + f;
}
else {
*Month = 4;
if (f == 26)
*Day = 19;
else if (f == 25 && d == 28)
*Day = 18;
else
*Day = f;
}
}
=========================================================================
Hope this helps,
Piet Starreveld
e-mail:101476.1040@compuserve.com